<?php
include 'include/functions.php';
include 'include/rss.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/MAIN.dwt.php" codeOutsideHTMLIsLocked="false" -->
  <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>JoshHughes.com NFL Football Pool</title>
    <!-- InstanceEndEditable -->
	<link rel="stylesheet" href="css/football.css" type="text/css">
    <script src="scripts/prototype.js" type="text/javascript"></script>
	<script src="scripts/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript">
	// Dynamic Iframe loader
	function loadIframe(theFrame, theURL) {
		document.getElementById(theFrame).src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = mainContent.document.body.scrollHeight
	 obj.style.height = docHeight + 'px'
	 } 
	</script>
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
	
		<?PHP include_once("layout/header.html"); ?>
		
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->
			<?php
				$news_feeds = array ('http://football.joshhughes.com/bb/rss/topics.php','http://msn.foxsports.com/feedout/syndicatedContent?categoryId=5','http://sports.espn.go.com/espn/rss/nfl/news','http://sports.yahoo.com/nfl/rss.xml','http://cbs.sportsline.com/partners/feeds/rss/nfl_news','http://www.msnbc.msn.com/id/3032874/device/rss/rss.xml','http://www.sportingnews.com/feeds/nfl/news.xml','http://rss.cnn.com/rss/si_nfl.rss');
				$news_feed_names = array ('Football Pool Forum','FOXSports NFL News','EPSN NFL News','Yahoo! NFL News','CBS Sportsline','MSNBC NFL News','The Sporting News','SI.com NFL News');
				$feedNum = 0;
				foreach ($news_feeds as $feed)
				{
					$feedNum++;
					?>
					<div style="width: 540px; background-color: #aaaaaa; padding: 3px;">
						<img src="../images/showhide.gif" title="Show/Hide News Feed <?=$feedNum;?>" alt="Show/Hide News Feed <?=$feedNum;?>" border="0" onclick="new Effect.toggle('news<?=$feedNum;?>', 'blind');"/> <span class="whitelink"><?=$news_feed_names[$feedNum-1];?></span>
						<div id="news<?=$feedNum;?>" style="background-color: #ffffff; padding-left: 5px; padding-bottom: 5px;
						<?
						if ($feedNum > 1)
							echo "display:none;";
						?>
						">
						<?
								set_time_limit(0);
								
								$file = $feed;
								
								$rss_channel = array();
								$currently_writing = "";
								$main = "";
								$item_counter = 0;		
																	
								$xml_parser = xml_parser_create();
								xml_set_element_handler($xml_parser, "startElement", "endElement");
								xml_set_character_data_handler($xml_parser, "characterData");
								if (!($fp = fopen($file, "r"))) {
									die("could not open XML input");
								}
								
								while ($data = fread($fp, 4096)) {
									if (!xml_parse($xml_parser, $data, feof($fp))) {
										die(sprintf("XML error: %s at line %d",
													xml_error_string(xml_get_error_code($xml_parser)),
													xml_get_current_line_number($xml_parser)));
									}
								}
								xml_parser_free($xml_parser);
								
								// output as HTML
								if (isset($rss_channel["IMAGE"])) {
									print ("<a href=\"" . $rss_channel["LINK"] . "\" target=\"_blank\"><img border=\"0\" src=\"" . $rss_channel["IMAGE"]["URL"] . "\" align=\"middle\" alt=\"" . $rss_channel["IMAGE"]["TITLE"] . "\"></a>&nbsp;&nbsp;<font size=\"5\">" . $rss_channel["TITLE"] . "</font><br/>");
								} else {
									print ("<h2 id=\"pageName\"><a href=\"".$file."\">" . $rss_channel["TITLE"] . "</a></h2>");
								}
								print ("<i>" . $rss_channel["DESCRIPTION"] . "</i><br/>");
								if (isset($rss_channel["ITEMS"])) {
									if (count($rss_channel["ITEMS"]) > 0)
									{
										$topOut = count($rss_channel["ITEMS"]);
										if ($topOut > 5)
											$topOut = 5;
										print ("<UL>");
										for($i = 0; $i < $topOut; $i++)
										{
											print ("\n<li><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\" target=\"_blank\" class=\"permLink\"><h4>" . $rss_channel["ITEMS"][$i]["TITLE"] . "</h4></a></li>");
										}
										print ("</UL>");
									} else {
										print ("<b>There are no articles in this feed.</b>");
									}
								}
							?>
							<a href="<?= $rss_channel["LINK"] ?>" class="permLink" target="_blank">More Headlines...</a>
						</div>
					</div>
					<br/>
					<?
				}
				?>

			<!-- InstanceEndEditable -->
			
			</div>
			<div id="leftcol" >
			
				<?PHP include_once("layout/left_column.php"); ?>
		
			</div>
			
		</div>
		
		<div id="footer" >
		
			<?PHP include_once("layout/footer.html"); ?>
			
		</div>
</div>
</body>
<!-- InstanceEnd --></html>